﻿/*
 * Erstellt mit SharpDevelop.
 * Benutzer: Kai Patrick
 * Datum: 31.03.2008
 * Zeit: 19:19
 * 
 * Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
 */

using System;
using System.Collections.Generic;
using Microsoft.Scripting;
using MSAst = Microsoft.Scripting.Ast;

namespace Gamadus.Engine.Compiler.Ast
{
	/// <summary>
	/// Description of StatementList.
	/// </summary>
	public class StatementList : Statement
	{
		private readonly Statement[] m_statements;
		
		public StatementList(Irony.Compiler.AstNode node) : base(node)
		{
			m_statements = new Statement[node.ChildNodes.Count];
			int i = 0;
			foreach(Irony.Compiler.AstNode child in node.ChildNodes)
			{
				m_statements[i++] = MakeStatement(child);
			}
		}
		
		public override string ToString()
		{
			string ret = "";
			foreach(Statement stmt in m_statements)
				ret += stmt.ToString()+"\n";
			
			return ret;
		}
		
		protected internal override MSAst.Expression Generate()
		{
			MSAst.Expression[] statements = new MSAst.Expression[m_statements.Length];
			int i = 0;
			foreach(Statement statement in m_statements)
			{
				statements[i++] = statement.Generate();
			}
			return MSAst.Ast.Block(statements);
		}
	}
}
